﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class ReceiptRepository : IReceiptRepository
    {
        private BuySoftwareOnlineDataContext context;

        public ReceiptRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Receipt> Receipts
        {
            get { return context.Receipts; }
        }

        public void SaveReceipt(Receipt receipt)
        {
            if (receipt.ReceiptID == 0)
            {
                context.Receipts.InsertOnSubmit(receipt);
            }
            else
            {
                context.Receipts.Attach(receipt);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, receipt);
            }
            context.SubmitChanges();
        }

        public void DeleteReceipt(Receipt receipt)
        {
            context.Receipts.DeleteOnSubmit(receipt);
            context.SubmitChanges();
        }
    }
}
